package com.example.demo.service.imply;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.annotation.AutoFill;
import com.example.demo.enumeration.OperationType;
import com.example.demo.mapper.UserMapper;
import com.example.demo.pojo.LoginInformation;
import com.example.demo.pojo.PublicFields;
import com.example.demo.pojo.dto.UserDTO;
import com.example.demo.pojo.entity.User;
import com.example.demo.pojo.vo.UserVO;
import com.example.demo.properties.JwtProperties;
import com.example.demo.service.IUserService;
import com.example.demo.utils.JwtUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Service
@RequiredArgsConstructor
public class IUserServiceImply extends ServiceImpl<UserMapper, User> implements IUserService{
    private final JwtProperties jwtProperties;
    private final UserMapper userMapper;
    @Override
    public User login(UserDTO userDTO) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(User::getUserName, userDTO.getUserName())
                .eq(User::getPassword, userDTO.getPassword());
        User user = userMapper.selectOne(wrapper);
        return user;
    }

    @Override
    public void logout() {

    }

    @Override
    public UserVO insert(UserDTO userDTO, PublicFields publicFields) {
        return null;
    }

    @Override
    public void updateUser(UserDTO userDTO, PublicFields publicFields) {

    }

    @Override
    @AutoFill(OperationType.INSERT)
    public void register(UserDTO userDTO, PublicFields publicFields) {
        User user = new User();
        BeanUtils.copyProperties(userDTO, user);
        BeanUtils.copyProperties(publicFields, user);
        baseMapper.insert(user);
    }

    @Override
    public UserVO getUserByUserId(Long id) {
        User user = baseMapper.selectById(id);
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user, userVO);
        return userVO;
    }
}
